package com.jambo.yudada.controller;

import com.jambo.yudada.common.BaseResponse;
import com.jambo.yudada.common.ErrorCode;
import com.jambo.yudada.common.ResultUtils;
import com.jambo.yudada.exception.ThrowUtils;
import com.jambo.yudada.mapper.UserAnswerMapper;
import com.jambo.yudada.model.dto.userAnswer.AppAnswerCountDTO;
import com.jambo.yudada.model.dto.userAnswer.AppAnswerResultCountDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/app/statistic")
@Slf4j
public class AppStatisticController {
@Resource
   private UserAnswerMapper userAnswerMapper;
@GetMapping("/answer_count")
    public BaseResponse<List<AppAnswerCountDTO>> getTop10App(){
    return ResultUtils.success(userAnswerMapper.getTop10App());
    }
    @GetMapping("/answer_count_by_appid")
    public BaseResponse<List<AppAnswerResultCountDTO>> getTop10AppByAppId(Long appId){
        ThrowUtils.throwIf(appId==null||appId<0, ErrorCode.PARAMS_ERROR);
        return ResultUtils.success(userAnswerMapper.doAppAnswerResultCount(appId));
    }
    }

